home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / tcp / samba_2.0.7.lha / source / amiga.diffs next >
Text File  |  2000-08-17  |  28KB  |  1,175 lines

  1. *** lib/system.c    Tue Apr 25 20:06:52 2000
  2. --- /new/lib/system.c    Mon May 22 19:02:10 2000
  3. ***************
  4. *** 795,955 ****
  5.   
  6.   FILE *sys_popen(const char *command, const char *mode, BOOL paranoid)
  7.   {
  8. !     int parent_end, child_end;
  9. !     int pipe_fds[2];
  10. !     popen_list *entry = NULL;
  11. !     char **argl = NULL;
  12. !     if (pipe(pipe_fds) < 0)
  13. !         return NULL;
  14. !     if (mode[0] == 'r' && mode[1] == '\0') {
  15. !         parent_end = pipe_fds[0];
  16. !         child_end = pipe_fds[1];
  17. !     } else if (mode[0] == 'w' && mode[1] == '\0') {
  18. !         parent_end = pipe_fds[1];
  19. !         child_end = pipe_fds[0];
  20. !     } else {
  21. !         errno = EINVAL;
  22. !         goto err_exit;
  23. !     }
  24. !     if (!*command) {
  25. !         errno = EINVAL;
  26. !         goto err_exit;
  27.       }
  28.   
  29. !     if((entry = (popen_list *)malloc(sizeof(popen_list))) == NULL)
  30. !         goto err_exit;
  31. !     /*
  32. !      * Extract the command and args into a NULL terminated array.
  33. !      */
  34.   
  35. !     if(!(argl = extract_args(command)))
  36. !         goto err_exit;
  37.   
  38. -     if(paranoid) {
  39.           /*
  40. !          * Do some basic paranioa checks. Do a stat on the parent
  41. !          * directory and ensure it's not world writable. Do a stat
  42. !          * on the file itself and ensure it's owned by root and not
  43. !          * world writable. Note this does *not* prevent symlink races,
  44. !          * but is a generic "don't let the admin screw themselves"
  45. !          * check.
  46.            */
  47.   
  48. !         SMB_STRUCT_STAT st;
  49. !         pstring dir_name;
  50. !         char *ptr = strrchr(argl[0], '/');
  51. !     
  52. !         if(sys_stat(argl[0], &st) != 0)
  53.               goto err_exit;
  54.   
  55. !         if((st.st_uid != (uid_t)0) || (st.st_mode & S_IWOTH)) {
  56. !             errno = EACCES;
  57. !             goto err_exit;
  58. !         }
  59. !         
  60. !         if(!ptr) {
  61.               /*
  62. !              * No '/' in name - use current directory.
  63.                */
  64. -             pstrcpy(dir_name, ".");
  65. -         } else {
  66.   
  67. !             /*
  68. !              * Copy into a pstring and do the checks
  69. !              * again (in case we were length tuncated).
  70. !              */
  71.   
  72. !             pstrcpy(dir_name, argl[0]);
  73. !             ptr = strrchr(dir_name, '/');
  74. !             if(!ptr) {
  75. !                 errno = EINVAL;
  76.                   goto err_exit;
  77.               }
  78. !             if(strcmp(dir_name, "/") != 0)
  79. !                 *ptr = '\0';
  80. !             if(!dir_name[0])
  81.                   pstrcpy(dir_name, ".");
  82.           }
  83.   
  84. !         if(sys_stat(argl[0], &st) != 0)
  85. !             goto err_exit;
  86.   
  87. -         if(!S_ISDIR(st.st_mode) || (st.st_mode & S_IWOTH)) {
  88. -             errno = EACCES;
  89.               goto err_exit;
  90.           }
  91. -     }
  92.   
  93. !     entry->child_pid = fork();
  94.   
  95. !     if (entry->child_pid == -1) {
  96. !         /*
  97. !          * Error !
  98. !          */
  99.   
  100. !         goto err_exit;
  101. !     }
  102.   
  103. !     if (entry->child_pid == 0) {
  104.   
  105. !         /*
  106. !          * Child !
  107. !          */
  108.   
  109. !         int child_std_end = (mode[0] == 'r') ? STDOUT_FILENO : STDIN_FILENO;
  110. !         popen_list *p;
  111.   
  112. !         close(parent_end);
  113. !         if (child_end != child_std_end) {
  114. !             dup2 (child_end, child_std_end);
  115. !             close (child_end);
  116.           }
  117.   
  118.           /*
  119. !          * POSIX.2:  "popen() shall ensure that any streams from previous
  120. !          * popen() calls that remain open in the parent process are closed
  121. !          * in the new child process."
  122.            */
  123.   
  124. !         for (p = popen_chain; p; p = p->next)
  125. !             close(fileno(p->fp));
  126. !         execv(argl[0], argl);
  127. !         _exit (127);
  128. !     }
  129. !     /*
  130. !      * Parent.
  131. !      */
  132. !     close (child_end);
  133. !     free((char *)argl);
  134. !     /*
  135. !      * Create the FILE * representing this fd.
  136. !      */
  137. !     entry->fp = fdopen(parent_end, mode);
  138. !     /* Link into popen_chain. */
  139. !     entry->next = popen_chain;
  140. !     popen_chain = entry;
  141. !     return entry->fp;
  142.   
  143. ! err_exit:
  144.   
  145. !     if(entry)
  146. !         free((char *)entry);
  147. !     if(argl)
  148. !         free((char *)argl);
  149. !     close(pipe_fds[0]);
  150. !     close(pipe_fds[1]);
  151. !     return NULL;
  152.   }
  153.   
  154.   /**************************************************************************
  155. --- 795,963 ----
  156.   
  157.   FILE *sys_popen(const char *command, const char *mode, BOOL paranoid)
  158.   {
  159. !     #ifdef AMIGA
  160. !     {
  161. !         return( amiga_popen(command,mode) );
  162.       }
  163. +     #else
  164. +     {
  165. +         int parent_end, child_end;
  166. +         int pipe_fds[2];
  167. +         popen_list *entry = NULL;
  168. +         char **argl = NULL;
  169. +         if (pipe(pipe_fds) < 0)
  170. +             return NULL;
  171. +         if (mode[0] == 'r' && mode[1] == '\0') {
  172. +             parent_end = pipe_fds[0];
  173. +             child_end = pipe_fds[1];
  174. +            } else if (mode[0] == 'w' && mode[1] == '\0') {
  175. +             parent_end = pipe_fds[1];
  176. +             child_end = pipe_fds[0];
  177. +         } else {
  178. +             errno = EINVAL;
  179. +             goto err_exit;
  180. +         }
  181.   
  182. !         if (!*command) {
  183. !             errno = EINVAL;
  184. !             goto err_exit;
  185. !         }
  186.   
  187. !         if((entry = (popen_list *)malloc(sizeof(popen_list))) == NULL)
  188. !             goto err_exit;
  189.   
  190.           /*
  191. !          * Extract the command and args into a NULL terminated array.
  192.            */
  193.   
  194. !         if(!(argl = extract_args(command)))
  195.               goto err_exit;
  196.   
  197. !         if(paranoid) {
  198.               /*
  199. !              * Do some basic paranioa checks. Do a stat on the parent
  200. !              * directory and ensure it's not world writable. Do a stat
  201. !              * on the file itself and ensure it's owned by root and not
  202. !              * world writable. Note this does *not* prevent symlink races,
  203. !              * but is a generic "don't let the admin screw themselves"
  204. !              * check.
  205.                */
  206.   
  207. !             SMB_STRUCT_STAT st;
  208. !             pstring dir_name;
  209. !             char *ptr = strrchr(argl[0], '/');
  210. !         
  211. !             if(sys_stat(argl[0], &st) != 0)
  212. !                 goto err_exit;
  213.   
  214. !             if((st.st_uid != (uid_t)0) || (st.st_mode & S_IWOTH)) {
  215. !                 errno = EACCES;
  216.                   goto err_exit;
  217.               }
  218. !             
  219. !             if(!ptr) {
  220. !                 /*
  221. !                  * No '/' in name - use current directory.
  222. !                  */
  223.                   pstrcpy(dir_name, ".");
  224. +             } else {
  225. +                 /*
  226. +                  * Copy into a pstring and do the checks
  227. +                  * again (in case we were length tuncated).
  228. +                  */
  229. +                 pstrcpy(dir_name, argl[0]);
  230. +                 ptr = strrchr(dir_name, '/');
  231. +                 if(!ptr) {
  232. +                     errno = EINVAL;
  233. +                     goto err_exit;
  234. +                 }
  235. +                 if(strcmp(dir_name, "/") != 0)
  236. +                     *ptr = '\0';
  237. +                 if(!dir_name[0])
  238. +                     pstrcpy(dir_name, ".");
  239. +             }
  240. +             if(sys_stat(argl[0], &st) != 0)
  241. +                 goto err_exit;
  242. +             if(!S_ISDIR(st.st_mode) || (st.st_mode & S_IWOTH)) {
  243. +                 errno = EACCES;
  244. +                 goto err_exit;
  245. +             }
  246.           }
  247.   
  248. !         entry->child_pid = fork();
  249. !         if (entry->child_pid == -1) {
  250. !             /*
  251. !              * Error !
  252. !              */
  253.   
  254.               goto err_exit;
  255.           }
  256.   
  257. !         if (entry->child_pid == 0) {
  258.   
  259. !             /*
  260. !              * Child !
  261. !              */
  262.   
  263. !             int child_std_end = (mode[0] == 'r') ? STDOUT_FILENO : STDIN_FILENO;
  264. !             popen_list *p;
  265.   
  266. !             close(parent_end);
  267. !             if (child_end != child_std_end) {
  268. !                 dup2 (child_end, child_std_end);
  269. !                 close (child_end);
  270. !             }
  271.   
  272. !             /*
  273. !              * POSIX.2:  "popen() shall ensure that any streams from previous
  274. !              * popen() calls that remain open in the parent process are closed
  275. !              * in the new child process."
  276. !              */
  277.   
  278. !             for (p = popen_chain; p; p = p->next)
  279. !                 close(fileno(p->fp));
  280.   
  281. !             execv(argl[0], argl);
  282. !             _exit (127);
  283.           }
  284.   
  285.           /*
  286. !          * Parent.
  287.            */
  288.   
  289. !         close (child_end);
  290. !         free((char *)argl);
  291.   
  292. !         /*
  293. !          * Create the FILE * representing this fd.
  294. !          */
  295. !         entry->fp = fdopen(parent_end, mode);
  296.   
  297. !         /* Link into popen_chain. */
  298. !         entry->next = popen_chain;
  299. !         popen_chain = entry;
  300. !         return entry->fp;
  301. !     err_exit:
  302. !         if(entry)
  303. !             free((char *)entry);
  304. !         if(argl)
  305. !             free((char *)argl);
  306. !         close(pipe_fds[0]);
  307. !         close(pipe_fds[1]);
  308. !         return NULL;
  309. !     }
  310. !     #endif /* AMIGA */
  311.   }
  312.   
  313.   /**************************************************************************
  314. ***************
  315. *** 958,995 ****
  316.   
  317.   int sys_pclose( FILE *fp)
  318.   {
  319. !     int wstatus;
  320. !     popen_list **ptr = &popen_chain;
  321. !     popen_list *entry = NULL;
  322. !     pid_t wait_pid;
  323. !     int status = -1;
  324. !     /* Unlink from popen_chain. */
  325. !     for ( ; *ptr != NULL; ptr = &(*ptr)->next) {
  326. !         if ((*ptr)->fp == fp) {
  327. !             entry = *ptr;
  328. !             *ptr = (*ptr)->next;
  329. !             status = 0;
  330. !             break;
  331. !         }
  332.       }
  333.   
  334. !     if (status < 0 || close(fileno(entry->fp)) < 0)
  335. !         return -1;
  336.   
  337. !     /*
  338. !      * As Samba is catching and eating child process
  339. !      * exits we don't really care about the child exit
  340. !      * code, a -1 with errno = ECHILD will do fine for us.
  341. !      */
  342. !     do {
  343. !         wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0);
  344. !     } while (wait_pid == -1 && errno == EINTR);
  345. !     free((char *)entry);
  346. !     if (wait_pid == -1)
  347. !         return -1;
  348. !     return wstatus;
  349.   }
  350. --- 966,1012 ----
  351.   
  352.   int sys_pclose( FILE *fp)
  353.   {
  354. !     #ifdef AMIGA
  355. !     {
  356. !         return( amiga_pclose(fp) );
  357.       }
  358. +     #else
  359. +     {
  360. +         int wstatus;
  361. +         popen_list **ptr = &popen_chain;
  362. +         popen_list *entry = NULL;
  363. +         pid_t wait_pid;
  364. +         int status = -1;
  365. +         /* Unlink from popen_chain. */
  366. +         for ( ; *ptr != NULL; ptr = &(*ptr)->next) {
  367. +             if ((*ptr)->fp == fp) {
  368. +                 entry = *ptr;
  369. +                 *ptr = (*ptr)->next;
  370. +                 status = 0;
  371. +                 break;
  372. +             }
  373. +         }
  374.   
  375. !         if (status < 0 || close(fileno(entry->fp)) < 0)
  376. !             return -1;
  377.   
  378. !         /*
  379. !          * As Samba is catching and eating child process
  380. !          * exits we don't really care about the child exit
  381. !          * code, a -1 with errno = ECHILD will do fine for us.
  382. !          */
  383. !         do {
  384. !             wait_pid = sys_waitpid (entry->child_pid, &wstatus, 0);
  385. !         } while (wait_pid == -1 && errno == EINTR);
  386. !         free((char *)entry);
  387. !         if (wait_pid == -1)
  388. !             return -1;
  389. !         return wstatus;
  390. !     }
  391. !     #endif /* AMIGA */
  392.   }
  393. *** lib/snprintf.c    Tue Apr 25 20:06:52 2000
  394. --- /new/lib/snprintf.c    Thu Aug 17 14:04:03 2000
  395. ***************
  396. *** 49,54 ****
  397. --- 49,59 ----
  398.    *    fixed handling of %.0f
  399.    *    added test for HAVE_LONG_DOUBLE
  400.    *
  401. +  *  Olaf Barthel <olsen@sourcery.han.de> 15-Oct-99
  402. +  *    Implemented the missing 'f' and 'g' floating point output
  403. +  *    formats; also fixed handling of floating point numbers
  404. +  *    like "0.01" which would always come out as "0.1".
  405. +  *
  406.    **************************************************************/
  407.   
  408.   #include "config.h"
  409. ***************
  410. *** 59,64 ****
  411. --- 64,73 ----
  412.   
  413.   #if !defined(HAVE_SNPRINTF) || !defined(HAVE_VSNPRINTF)
  414.   
  415. + #ifdef AMIGA
  416. + #include <math.h>
  417. + #endif /* AMIGA */
  418.   /* Define this as a fall through, HAVE_STDARG_H is probably already set */
  419.   
  420.   #define HAVE_VARARGS_H
  421. ***************
  422. *** 107,113 ****
  423.   static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
  424.               long value, int base, int min, int max, int flags);
  425.   static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
  426. !            LDOUBLE fvalue, int min, int max, int flags);
  427.   static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
  428.   
  429.   /*
  430. --- 116,122 ----
  431.   static void fmtint (char *buffer, size_t *currlen, size_t maxlen,
  432.               long value, int base, int min, int max, int flags);
  433.   static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
  434. !            LDOUBLE fvalue, int min, int max, int flags, char ch);
  435.   static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
  436.   
  437.   /*
  438. ***************
  439. *** 326,332 ****
  440.       else
  441.         fvalue = va_arg (args, double);
  442.       /* um, floating point? */
  443. !     fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags);
  444.       break;
  445.         case 'E':
  446.       flags |= DP_F_UP;
  447. --- 335,341 ----
  448.       else
  449.         fvalue = va_arg (args, double);
  450.       /* um, floating point? */
  451. !     fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags, ch);
  452.       break;
  453.         case 'E':
  454.       flags |= DP_F_UP;
  455. ***************
  456. *** 335,340 ****
  457. --- 344,351 ----
  458.         fvalue = va_arg (args, LDOUBLE);
  459.       else
  460.         fvalue = va_arg (args, double);
  461. +     /* um, floating point? */
  462. +     fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags, ch);
  463.       break;
  464.         case 'G':
  465.       flags |= DP_F_UP;
  466. ***************
  467. *** 343,348 ****
  468. --- 354,361 ----
  469.         fvalue = va_arg (args, LDOUBLE);
  470.       else
  471.         fvalue = va_arg (args, double);
  472. +     /* um, floating point? */
  473. +     fmtfp (buffer, &currlen, maxlen, fvalue, min, max, flags, ch);
  474.       break;
  475.         case 'c':
  476.       dopr_outch (buffer, &currlen, maxlen, va_arg (args, int));
  477. ***************
  478. *** 577,584 ****
  479.   }
  480.   
  481.   static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
  482. !            LDOUBLE fvalue, int min, int max, int flags)
  483.   {
  484.     int signvalue = 0;
  485.     LDOUBLE ufvalue;
  486.   #ifndef HAVE_FCVT
  487. --- 590,604 ----
  488.   }
  489.   
  490.   static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
  491. !            LDOUBLE fvalue, int min, int max, int flags, char ch)
  492.   {
  493. +   enum /* olsen: output formats to be used below. */
  494. +   {
  495. +     FORMAT_f,
  496. +     FORMAT_g,
  497. +     FORMAT_e
  498. +   };
  499.     int signvalue = 0;
  500.     LDOUBLE ufvalue;
  501.   #ifndef HAVE_FCVT
  502. ***************
  503. *** 593,599 ****
  504. --- 613,621 ----
  505.   # ifdef HAVE_FCVTL
  506.     extern char *fcvtl(long double value, int ndigit, int *decpt, int *sign);
  507.   # else
  508. + #ifndef AMIGA
  509.     extern char *fcvt(double value, int ndigit, int *decpt, int *sign);
  510. + #endif /* AMIGA */
  511.   # endif
  512.   #endif
  513.     int iplace = 0;
  514. ***************
  515. *** 603,609 ****
  516.     int caps = 0;
  517.     long intpart;
  518.     long fracpart;
  519. !   
  520.     /* 
  521.      * AIX manpage says the default is 0, but Solaris says the default
  522.      * is 6, and sprintf on AIX defaults to 6
  523. --- 625,635 ----
  524.     int caps = 0;
  525.     long intpart;
  526.     long fracpart;
  527. !   int exponent;
  528. !   int exponentLen;
  529. !   int outputFmt;
  530. !   int decimalPointLen;
  531.     /* 
  532.      * AIX manpage says the default is 0, but Solaris says the default
  533.      * is 6, and sprintf on AIX defaults to 6
  534. ***************
  535. *** 622,627 ****
  536. --- 648,696 ----
  537.         if (flags & DP_F_SPACE)
  538.       signvalue = ' ';
  539.   
  540. +   /* olsen: determine the output format. */
  541. +   if(ch == 'g' || ch == 'G')
  542. +     outputFmt = FORMAT_g;
  543. +   else if (ch == 'e' || ch == 'E')
  544. +     outputFmt = FORMAT_e;
  545. +   else
  546. +     outputFmt = FORMAT_f;
  547. +   /* olsen: calculate the exponent */
  548. +   exponent = 0;
  549. +   if(ufvalue > 0.0 && outputFmt != FORMAT_f)
  550. +   {
  551. +     LDOUBLE value = ufvalue;
  552. +     /* Make sure that the integer part
  553. +      * comes out as a single digit.
  554. +      */
  555. +     if(value < 1.0)
  556. +     {
  557. +       do
  558. +       {
  559. +         value *= 10.0;
  560. +         exponent--;
  561. +       }
  562. +       while(value < 1.0);
  563. +     }
  564. +     else if(value > 10.0)
  565. +     {
  566. +       do
  567. +       {
  568. +         value /= 10.0;
  569. +         exponent++;
  570. +       }
  571. +       while(value > 10.0);
  572. +     }
  573. +     /* Don't change the base unless we are to output
  574. +      * the number in scientific format.
  575. +      */
  576. +     if((outputFmt == FORMAT_e) || (outputFmt == FORMAT_g && exponent < -4))
  577. +       ufvalue = value;
  578. +   }
  579.   #if 0
  580.     if (flags & DP_F_UP) caps = 1; /* Should characters be upper case? */
  581.   #endif
  582. ***************
  583. *** 659,674 ****
  584.       intpart = (intpart / 10);
  585.     } while(intpart && (iplace < 20));
  586.     if (iplace == 20) iplace--;
  587. !   iconvert[iplace] = 0;
  588.   
  589.     /* Convert fractional part */
  590.     do {
  591.       fconvert[fplace++] =
  592.         (caps? "0123456789ABCDEF":"0123456789abcdef")[fracpart % 10];
  593.       fracpart = (fracpart / 10);
  594. !   } while(fracpart && (fplace < 20));
  595.     if (fplace == 20) fplace--;
  596. !   fconvert[fplace] = 0;
  597.   #else  /* use fcvt() */
  598.     if (max > 310)
  599.       max = 310;
  600. --- 728,752 ----
  601.       intpart = (intpart / 10);
  602.     } while(intpart && (iplace < 20));
  603.     if (iplace == 20) iplace--;
  604. !   iconvert[iplace] = '\0';
  605.   
  606.     /* Convert fractional part */
  607.     do {
  608.       fconvert[fplace++] =
  609.         (caps? "0123456789ABCDEF":"0123456789abcdef")[fracpart % 10];
  610.       fracpart = (fracpart / 10);
  611. !   } while(fracpart != 0 && (fplace < 20));
  612. !   /* olsen: we need to make up for numbers like 0.01
  613. !    *        which would come out as "0.1" unless
  614. !    *        we add a few padding zeroes.
  615. !    */
  616. !   while(fplace < 20 && fplace < max)
  617. !     fconvert[fplace++] = '0';
  618.     if (fplace == 20) fplace--;
  619. !   fconvert[fplace] = '\0';
  620.   #else  /* use fcvt() */
  621.     if (max > 310)
  622.       max = 310;
  623. ***************
  624. *** 724,731 ****
  625.     }
  626.   #endif /* fcvt */
  627.     
  628.     /* -1 for decimal point, another -1 if we are printing a sign */
  629. !   padlen = min - iplace - max - 1 - ((signvalue) ? 1 : 0); 
  630.     zpadlen = max - fplace;
  631.     if (zpadlen < 0)
  632.       zpadlen = 0;
  633. --- 802,871 ----
  634.     }
  635.   #endif /* fcvt */
  636.     
  637. +   /* olsen: eliminate trailing zeroes. */
  638. +   decimalPointLen = (max > 0) ? 1 : 0;
  639. +   exponentLen = 0;
  640. +   if(outputFmt == FORMAT_g)
  641. +   {
  642. +     int i,numTrailingZeroes;
  643. +     /* Count the number of trailing zeroes. */
  644. +     numTrailingZeroes = 0;
  645. +     for(i = 0 ; i < fplace ; i++)
  646. +     {
  647. +       if(fconvert[i] == '0')
  648. +         numTrailingZeroes++;
  649. +       else
  650. +         break;
  651. +     }
  652. +     /* If there are any, remove them. */
  653. +     if(numTrailingZeroes > 0)
  654. +     {
  655. +       /* Remove the zeroes, if necessary.
  656. +        * Otherwise, just forget that we
  657. +        * had any digits in the fractional
  658. +        * part.
  659. +        */
  660. +       if(numTrailingZeroes != fplace)
  661. +       {
  662. +         for(i = 0 ; i < fplace-numTrailingZeroes ; i++)
  663. +           fconvert[i] = fconvert[numTrailingZeroes+i];
  664. +       }
  665. +       fplace -= numTrailingZeroes;
  666. +       fconvert[fplace] = '\0';
  667. +       /* Don't print the decimal point if
  668. +        * there is nothing to follow it.
  669. +        */
  670. +       if(fplace == 0)
  671. +         decimalPointLen = 0;
  672. +     }
  673. +     /* Switch to scientific output format
  674. +      * if the exponent is too small.
  675. +      */
  676. +     if(exponent < -4)
  677. +     {
  678. +       /* Two digits for the "e+" and
  679. +        * at least two digits for the number
  680. +        * to follow the sign.
  681. +        */
  682. +       exponentLen = (int)log10((LDOUBLE)exponent) + 2;
  683. +       if(exponentLen < 4)
  684. +         exponentLen = 4;
  685. +     }
  686. +   }
  687. +   else if(outputFmt == FORMAT_e)
  688. +   {
  689. +     exponentLen = (int)log10((LDOUBLE)exponent) + 2;
  690. +     if(exponentLen < 4)
  691. +       exponentLen = 4;
  692. +   }
  693.     /* -1 for decimal point, another -1 if we are printing a sign */
  694. !   padlen = min - iplace - max - decimalPointLen - ((signvalue) ? 1 : 0); 
  695.     zpadlen = max - fplace;
  696.     if (zpadlen < 0)
  697.       zpadlen = 0;
  698. ***************
  699. *** 734,739 ****
  700. --- 874,883 ----
  701.     if (flags & DP_F_MINUS) 
  702.       padlen = -padlen; /* Left Justifty */
  703.   
  704. +   /* olsen: eliminate trailing zeroes. */
  705. +   if(outputFmt == FORMAT_g)
  706. +     zpadlen = 0;
  707.     if ((flags & DP_F_ZERO) && (padlen > 0)) 
  708.     {
  709.       if (signvalue) 
  710. ***************
  711. *** 768,774 ****
  712.      * Decimal point.  This should probably use locale to find the correct
  713.      * char to print out.
  714.      */
  715. !   if (max > 0) {
  716.         dopr_outch (buffer, currlen, maxlen, '.');
  717.   
  718.         while (fplace > 0) 
  719. --- 912,918 ----
  720.      * Decimal point.  This should probably use locale to find the correct
  721.      * char to print out.
  722.      */
  723. !   if (max > 0 && decimalPointLen > 0) {
  724.         dopr_outch (buffer, currlen, maxlen, '.');
  725.   
  726.         while (fplace > 0) 
  727. ***************
  728. *** 781,786 ****
  729. --- 925,959 ----
  730.       --zpadlen;
  731.     }
  732.   
  733. +   /* olsen: output the exponent */
  734. +   if(exponentLen > 0)
  735. +   {
  736. +     char expChars[10];
  737. +     int numExpChars;
  738. +     int i;
  739. +     dopr_outch (buffer, currlen, maxlen, caps?'E':'e');
  740. +     if(exponent < 0)
  741. +     {
  742. +       dopr_outch (buffer, currlen, maxlen, '-');
  743. +       exponent = (-exponent);
  744. +     }
  745. +     else
  746. +     {
  747. +       dopr_outch (buffer, currlen, maxlen, '+');
  748. +     }
  749. +     numExpChars = 0;
  750. +     for(i = 0 ; i < exponentLen-2 && i < sizeof(expChars)-1 ; i++)
  751. +     {
  752. +       expChars[numExpChars++] = '0' + (exponent % 10);
  753. +       exponent /= 10;
  754. +     }
  755. +     while(numExpChars > 0)
  756. +       dopr_outch (buffer, currlen, maxlen, expChars[--numExpChars]);
  757. +   }
  758.     while (padlen < 0) 
  759.     {
  760.       dopr_outch (buffer, currlen, maxlen, ' ');
  761. ***************
  762. *** 856,861 ****
  763. --- 1029,1063 ----
  764.       "%3.2f",
  765.       "%.0f",
  766.       "%.1f",
  767. +     "%-1.5g",
  768. +     "%1.5g",
  769. +     "%123.9g",
  770. +     "%10.5g",
  771. +     "% 10.5g",
  772. +     "%+22.9g",
  773. +     "%+4.9g",
  774. +     "%01.3g",
  775. +     "%4g",
  776. +     "%3.1g",
  777. +     "%3.2g",
  778. +     "%.0g",
  779. +     "%.1g",
  780. +     "%-1.5e",
  781. +     "%1.5e",
  782. +     "%123.9e",
  783. +     "%10.5e",
  784. +     "% 10.5e",
  785. +     "%+22.9e",
  786. +     "%+4.9e",
  787. +     "%01.3e",
  788. +     "%4e",
  789. +     "%3.1e",
  790. +     "%3.2e",
  791. +     "%.0e",
  792. +     "%.1e",
  793.       NULL
  794.     };
  795.     double fp_nums[] = { -1.5, 134.21, 91340.2, 341.1234, 0203.9, 0.96, 0.996, 
  796. ***************
  797. *** 908,912 ****
  798.       }
  799.     printf ("%d tests failed out of %d.\n", fail, num);
  800.   }
  801. ! #endif /* SNPRINTF_TEST */
  802.   
  803. --- 1110,1114 ----
  804.       }
  805.     printf ("%d tests failed out of %d.\n", fail, num);
  806.   }
  807. ! #endif /* TEST_SNPRINTF */
  808.   
  809. *** lib/smbrun.c    Tue Jul 20 22:25:09 1999
  810. --- /new/lib/smbrun.c    Mon May 22 18:36:17 2000
  811. ***************
  812. *** 91,96 ****
  813. --- 91,99 ----
  814.       set_process_capability(KERNEL_OPLOCK_CAPABILITY, False);
  815.       set_inherited_process_capability(KERNEL_OPLOCK_CAPABILITY, False);
  816.   
  817. + #ifdef AMIGA
  818. +     return(amiga_smbrun(cmd,outfile,shared));
  819. + #else
  820.   #ifndef HAVE_EXECL
  821.       int ret;
  822.       pstring syscmd;  
  823. ***************
  824. *** 195,198 ****
  825. --- 198,202 ----
  826.       exit(82);
  827.   #endif
  828.       return 1;
  829. + #endif /* AMIGA */
  830.   }
  831. *** lib/util.c    Tue Apr 25 20:06:53 2000
  832. --- /new/lib/util.c    Mon May 22 18:01:33 2000
  833. ***************
  834. *** 1517,1522 ****
  835. --- 1517,1529 ----
  836.   ****************************************************************************/
  837.   void become_daemon(void)
  838.   {
  839. +     #ifdef AMIGA
  840. +     {
  841. +         DEBUG(2,("Warning: become_daemon() not done.\n"));
  842. +         return;
  843. +     }
  844. +     #endif /* AMIGA */
  845.       if (fork()) {
  846.           _exit(0);
  847.       }
  848. *** lib/interface.c    Wed Oct 13 02:26:48 1999
  849. --- /new/lib/interface.c    Mon May 22 18:01:33 2000
  850. ***************
  851. *** 234,243 ****
  852.   
  853.       n = get_interfaces(ifaces, MAX_INTERFACES);
  854.   
  855. !     if (n != total_probed ||
  856. !         memcmp(ifaces, probed_ifaces, sizeof(ifaces[0])*n)) {
  857. !         return True;
  858.       }
  859.       
  860.       return False;
  861.   }
  862. --- 234,255 ----
  863.   
  864.       n = get_interfaces(ifaces, MAX_INTERFACES);
  865.   
  866. !     /* olsen: probed_ifaces can be NULL! */
  867. !     #ifdef AMIGA
  868. !     {
  869. !         if (n != total_probed ||
  870. !             (probed_ifaces != NULL && memcmp(ifaces, probed_ifaces, sizeof(ifaces[0])*n))) {
  871. !             return True;
  872. !         }
  873.       }
  874. +     #else
  875. +     {
  876. +         if (n != total_probed ||
  877. +             memcmp(ifaces, probed_ifaces, sizeof(ifaces[0])*n)) {
  878. +             return True;
  879. +         }
  880. +     }
  881. +     #endif
  882.       
  883.       return False;
  884.   }
  885. *** lib/interfaces.c    Tue Apr 25 20:06:50 2000
  886. --- /new/lib/interfaces.c    Mon May 22 18:01:33 2000
  887. ***************
  888. *** 335,340 ****
  889. --- 335,349 ----
  890.       return total;
  891.   }
  892.   
  893. + #elif defined(AMIGA)
  894. + static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
  895. + {
  896. +     extern int amiga_get_interfaces(struct iface_struct * ifaces,int max_interfaces);
  897. +     return(amiga_get_interfaces(ifaces,max_interfaces));
  898. + }
  899.   #else /* a dummy version */
  900.   static int _get_interfaces(struct iface_struct *ifaces, int max_interfaces)
  901.   {
  902. *** web/cgi.c    Tue Apr 25 20:07:17 2000
  903. --- /new/web/cgi.c    Mon May 22 18:49:31 2000
  904. ***************
  905. *** 198,204 ****
  906.       }
  907.   
  908.       fclose(stdin);
  909. !     (void)open("/dev/null", O_RDWR);
  910.   
  911.       if ((s=query_string) || (s=getenv("QUERY_STRING"))) {
  912.           for (tok=strtok(s,"&;");tok;tok=strtok(NULL,"&;")) {
  913. --- 198,209 ----
  914.       }
  915.   
  916.       fclose(stdin);
  917. !     #ifndef AMIGA
  918. !     {
  919. !         (void)open("/dev/null", O_RDWR);
  920. !     }
  921. !     #endif /* AMIGA */
  922.   
  923.       if ((s=query_string) || (s=getenv("QUERY_STRING"))) {
  924.           for (tok=strtok(s,"&;");tok;tok=strtok(NULL,"&;")) {
  925. *** web/swat.c    Tue Apr 25 20:07:17 2000
  926. --- /new/web/swat.c    Mon May 22 18:01:38 2000
  927. ***************
  928. *** 980,987 ****
  929.       if (!dbf) dbf = stderr;
  930.   
  931.       /* we don't want stderr screwing us up */
  932. !     close(2);
  933. !     open("/dev/null", O_WRONLY);
  934.   
  935.       while ((opt = getopt(argc, argv,"s:a")) != EOF) {
  936.           switch (opt) {
  937. --- 980,991 ----
  938.       if (!dbf) dbf = stderr;
  939.   
  940.       /* we don't want stderr screwing us up */
  941. !     #ifndef AMIGA
  942. !     {
  943. !         close(2);
  944. !         open("/dev/null", O_WRONLY);
  945. !     }
  946. !     #endif /* AMIGA */
  947.   
  948.       while ((opt = getopt(argc, argv,"s:a")) != EOF) {
  949.           switch (opt) {
  950. *** smbd/reply.c    Tue Apr 25 22:06:22 2000
  951. --- /new/smbd/reply.c    Mon May 22 18:01:38 2000
  952. ***************
  953. *** 971,977 ****
  954.       char *p;
  955.       set_message(outbuf,3,3,True);
  956.       p = smb_buf(outbuf);
  957. !     pstrcpy(p,"Unix"); p = skip_string(p,1);
  958.       pstrcpy(p,"Samba "); pstrcat(p,VERSION); p = skip_string(p,1);
  959.       pstrcpy(p,global_myworkgroup); p = skip_string(p,1);
  960.       set_message(outbuf,3,PTR_DIFF(p,smb_buf(outbuf)),False);
  961. --- 971,985 ----
  962.       char *p;
  963.       set_message(outbuf,3,3,True);
  964.       p = smb_buf(outbuf);
  965. !     #ifdef AMIGA
  966. !     {
  967. !       pstrcpy(p,"AmigaOS"); p = skip_string(p,1);
  968. !     }
  969. !     #else
  970. !     {
  971. !       pstrcpy(p,"Unix"); p = skip_string(p,1);
  972. !     }
  973. !     #endif /* AMIGA */
  974.       pstrcpy(p,"Samba "); pstrcat(p,VERSION); p = skip_string(p,1);
  975.       pstrcpy(p,global_myworkgroup); p = skip_string(p,1);
  976.       set_message(outbuf,3,PTR_DIFF(p,smb_buf(outbuf)),False);
  977. *** passdb/smbpass.c    Tue Apr 25 20:07:01 2000
  978. --- /new/passdb/smbpass.c    Mon May 22 18:53:19 2000
  979. ***************
  980. *** 148,161 ****
  981.     /* Set a buffer to do more efficient reads */
  982.     setvbuf(fp, (char *)NULL, _IOFBF, 1024);
  983.   
  984.     /* Make sure it is only rw by the owner */
  985. !   if(fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1) {
  986. !     DEBUG(0, ("startsmbfilepwent_internal: failed to set 0600 permissions on password file %s. \
  987.   Error was %s\n.", pfile, strerror(errno) ));
  988. !     pw_file_unlock(fileno(fp), lock_depth);
  989. !     fclose(fp);
  990. !     return NULL;
  991.     }
  992.   
  993.     /* We have a lock on the file. */
  994.     return (void *)fp;
  995. --- 148,165 ----
  996.     /* Set a buffer to do more efficient reads */
  997.     setvbuf(fp, (char *)NULL, _IOFBF, 1024);
  998.   
  999. +   #ifndef AMIGA
  1000. +   {
  1001.     /* Make sure it is only rw by the owner */
  1002. !     if(fchmod(fileno(fp), S_IRUSR|S_IWUSR) == -1) {
  1003. !       DEBUG(0, ("startsmbfilepwent_internal: failed to set 0600 permissions on password file %s. \
  1004.   Error was %s\n.", pfile, strerror(errno) ));
  1005. !       pw_file_unlock(fileno(fp), lock_depth);
  1006. !       fclose(fp);
  1007. !       return NULL;
  1008. !     }
  1009.     }
  1010. +   #endif /* AMIGA */
  1011.   
  1012.     /* We have a lock on the file. */
  1013.     return (void *)fp;
  1014. *** include/includes.h    Tue Apr 25 20:06:46 2000
  1015. --- /new/include/includes.h    Mon May 22 18:01:26 2000
  1016. ***************
  1017. *** 21,26 ****
  1018. --- 21,36 ----
  1019.      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  1020.   */
  1021.   
  1022. + #ifdef AMIGA
  1023. + /* This type definition clashes with one
  1024. +  * used in the Samba code, which is why
  1025. +  * we hide it.
  1026. +  */
  1027. + #define BOOL __BOOL
  1028. + #include <exec/types.h>
  1029. + #undef BOOL
  1030. + #endif /* AMIGA */
  1031.   #ifndef NO_CONFIG_H /* for some tests */
  1032.   #include "config.h"
  1033.   #endif
  1034. ***************
  1035. *** 880,885 ****
  1036. --- 890,906 ----
  1037.   
  1038.   /* yuck, I'd like a better way of doing this */
  1039.   #define DIRP_SIZE (256 + 32)
  1040. + #ifdef AMIGA
  1041. + /* Remap a couple of library routines. */
  1042. + #include "amiga.h"
  1043. + /* These clash with local definitions in "smbd/ipc.c",
  1044. +  * which is why we undefine them.
  1045. +  */
  1046. + #undef ACCESS_READ
  1047. + #undef ACCESS_WRITE
  1048. + #endif /* AMIGA */
  1049.   
  1050.   /*
  1051.    * glibc on linux doesn't seem to have MSG_WAITALL
  1052. *** libsmb/clientgen.c    Tue Apr 25 20:06:54 2000
  1053. --- /new/libsmb/clientgen.c    Mon May 22 18:01:36 2000
  1054. ***************
  1055. *** 876,882 ****
  1056.           pstrcpy(p,workgroup);
  1057.           strupper(p);
  1058.           p = skip_string(p,1);
  1059. !         pstrcpy(p,"Unix");p = skip_string(p,1);
  1060.           pstrcpy(p,"Samba");p = skip_string(p,1);
  1061.           set_message(cli->outbuf,13,PTR_DIFF(p,smb_buf(cli->outbuf)),False);
  1062.       }
  1063. --- 876,890 ----
  1064.           pstrcpy(p,workgroup);
  1065.           strupper(p);
  1066.           p = skip_string(p,1);
  1067. !         #ifdef AMIGA
  1068. !         {
  1069. !           pstrcpy(p,"AmigaOS");p = skip_string(p,1);
  1070. !         }
  1071. !         #else
  1072. !         {
  1073. !           pstrcpy(p,"Unix");p = skip_string(p,1);
  1074. !         }
  1075. !         #endif /* AMIGA */
  1076.           pstrcpy(p,"Samba");p = skip_string(p,1);
  1077.           set_message(cli->outbuf,13,PTR_DIFF(p,smb_buf(cli->outbuf)),False);
  1078.       }
  1079. *** utils/testparm.c    Wed Oct 13 02:27:03 1999
  1080. --- /new/utils/testparm.c    Thu Aug 17 14:42:14 2000
  1081. ***************
  1082. *** 70,78 ****
  1083.                  lp_lockdir());
  1084.           ret = 1;
  1085.       } else if ((st.st_mode & 0777) != 0755) {
  1086. !         printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n",
  1087. !                lp_lockdir());
  1088. !         ret = 1;
  1089.       }
  1090.   
  1091.       /*
  1092. --- 70,88 ----
  1093.                  lp_lockdir());
  1094.           ret = 1;
  1095.       } else if ((st.st_mode & 0777) != 0755) {
  1096. !         /* olsen: This is not necessary on the Amiga and always
  1097. !          *        seems to be a source of confusion when users
  1098. !          *        try to determine what's wrong with their
  1099. !          *        configurations.
  1100. !          */
  1101. !         #ifndef AMIGA
  1102. !         {
  1103. !             printf("WARNING: lock directory %s should have permissions 0755 for browsing to work\n",
  1104. !                    lp_lockdir());
  1105. !             ret = 1;
  1106. !         }
  1107. !         #endif /* AMIGA */
  1108.       }
  1109.   
  1110.       /*
  1111.